﻿using System.Web.Mvc;
using Dexter.Domain.Model;
using Dexter.Logger.Contracts;
using Dexter.Search;
using Dexter.Services;
using Dexter.Web.Utils;

namespace Dexter.Web.Mvc.Controllers.FrontEnd {
	public class RedirectController : PublicControllerBase {
		public RedirectController(ISearchService searchService, ICommentService commentService, IReferrerService referrerService, IConfigurationService configurationService, IWebUtils webUtils, ILogger logger, IUrlBuilder urlBuilder, IBlogRollService blogRollService, ICategoryService categoryService, IPostService postService, IThemeManager themeManager, ITagService tagService, IPageService pageService) : base(searchService, commentService, referrerService, configurationService, webUtils, logger, urlBuilder, blogRollService, categoryService, postService, themeManager, tagService, pageService) {}

		[AcceptVerbs(HttpVerbs.Get)]
		public ActionResult Index(int? id, string url) {
			RedirectType redirect = RedirectType.Unknown;

			if(id.HasValue)
				redirect = (RedirectType)id.Value;

			switch (redirect)
			{
				case RedirectType.Unknown:
					return Redirect(url);
				case RedirectType.Permanent:
					return RedirectPermanent(url);
				case RedirectType.NotFound:
					return HttpNotFound();
				default:
					return HttpNotFound();
			}
		}
	}
}